import network from '@/utils/network'
import baseUrl from './baseUrl'
import commonJs from '@/utils/common'
import qs from 'qs'

const BASE_URL = baseUrl + '/Asset'

export default {
  getPageList(data) {
    return network.request({
      url: BASE_URL + '/GetPageList',
      method: 'post',
      data
    })
  },

  excelUploadUrl: BASE_URL + '/importExcel',
  uploadAttachUrl: BASE_URL + '/uploadAttach',
  delAttachUrl: BASE_URL + '/delAttach',
  getPrintQrcode(id) {
    return BASE_URL + '/getPrintQrcode/id/' + id
  },
  getDetailsQrcode(id) {
    return BASE_URL + '/getDetailsQrcode/id/' + id
  },
  getDetails(id) {
    return network.request({
      url: BASE_URL + '/getDetails',
      method: 'get',
      params: { id }
    })
  },
  getForm(id) {
    return network.request({
      url: BASE_URL + '/getForm',
      method: 'get',
      params: {
        id
      }
    })
  },
  getTaskForm(id) {
    return network.request({
      url: BASE_URL + '/getTaskForm',
      method: 'get',
      params: {
        id
      }
    })
  },
  getPrint(id) {
    return network.request({
      url: BASE_URL + '/getPrint',
      method: 'get',
      params: {
        id
      }
    })
  },
  getSummary(params) {
    params = commonJs.obj.removeNullKey(params)
    return rnetwork.equest({
      url: BASE_URL + '/getSummary',
      method: 'get',
      params
    })
  },
  getList(params) {
    params = commonJs.obj.removeNullKey(params)
    return network.request({
      url: BASE_URL + '/getList',
      method: 'get',
      params
    })
  },
  getProductList(params) {
    params = commonJs.obj.removeNullKey(params)
    return network.request({
      url: BASE_URL + '/getProductList',
      method: 'get',
      params
    })
  },
  create() {
    return network.request({
      url: BASE_URL + '/create',
      method: 'post'
    })
  },
  update(data) {
    data = commonJs.obj.copyByKey(data, [
      'id',
      'action',
      'company_id',
      'type_id',
      'supplier_id',
      'model',
      'diy_no',
      'inbound_date',
      'price',
      'amount',
      'sn',
      'source',
      'is_stock_warning',
      'stock_warning_id',
      'remarks'
    ])
    return network.request({
      url: BASE_URL + '/update',
      method: 'post',
      data
    })
  },
  del(id) {
    return network.request({
      url: BASE_URL + '/del',
      method: 'post',
      data: {
        id
      }
    })
  },
  undo(id) {
    return network.request({
      url: BASE_URL + '/undo',
      method: 'post',
      data: {
        id
      }
    })
  },
  undoReview(id) {
    return network.request({
      url: BASE_URL + '/undoReview',
      method: 'post',
      data: {
        id
      }
    })
  },
  getSummaryData(params) {
    params = commonJs.obj.removeNullKey(params)
    return network.request({
      url: BASE_URL + '/getSummaryData',
      method: 'get',
      params
    })
  },
  loadFinish(task_id) {
    return network.request({
      url: BASE_URL + '/loadFinish',
      method: 'post',
      data: {
        task_id
      }
    })
  },
  undoLoadFinish(task_id) {
    return network.request({
      url: BASE_URL + '/undoLoadFinish',
      method: 'post',
      data: {
        task_id
      }
    })
  },
  review(data) {
    data = commonJs.obj.copyByKey(data, ['id'])
    return network.request({
      url: BASE_URL + '/review',
      method: 'post',
      data
    })
  },
  driverSupply(data) {
    data = commonJs.obj.copyByKey(data, [
      'id', 'driver_unit', 'driver_no', 'driver_name', 'driver_tel'])
    return network.request({
      url: BASE_URL + '/driverSupply',
      method: 'post',
      data
    })
  },
  exportExcel(params) {
    params = commonJs.obj.removeNullKey(params)
    let queryStr = qs.stringify(params)
    window.open(BASE_URL + '/exportExcel?' + queryStr);
  },
  getNearMonthSummary(params = {}) {
    params = commonJs.obj.removeNullKey(params)
    return network.request({
      url: BASE_URL + '/getNearMonthSummary ',
      method: 'get',
      params
    })
  },
  getTimeStatistic(params) {
    params = commonJs.obj.removeNullKey(params)
    return network.request({
      url: BASE_URL + '/getTimeStatistic',
      method: 'get',
      params
    })
  },
  getFieldList({ field, keyword }) {
    return network.request({
      url: BASE_URL + '/getFieldList',
      method: 'get',
      params: {
        field, keyword
      }
    })
  }
}